// 设备档案 模块

import { SystemSpace } from "@/api/interface/archive"
import { ResPage } from "@/api/interface/index"
import http from "@/api"

// ------------------生产设备------------------ //
// 生产设备 分页查询
export const devicePage = (params: SystemSpace.DevicePageQuery) => {
  return http.post<ResPage<SystemSpace.DevicePage>>("/device/page", params)
}
// 生产设备 新增
export const addDevice = (params: SystemSpace.SaveDevice) => {
  return http.post<any>("/device/add", params)
}
// 生产设备 编辑
export const modifyDevice = (params: SystemSpace.SaveDevice) => {
  return http.post<any>("/device/modify", params)
}
// 生产设备 删除
export const deleteDevice = (params: { id: number }) => {
  return http.post<any>("/device/remove", params)
}
// 生产设备 列表
export const deviceList = (params?: SystemSpace.DeviceListQuery) => {
  return http.get<SystemSpace.DeviceList[]>("/device/list", params)
}
// 生产设备 列表
export const deviceListEnergy = (params?: SystemSpace.DeviceListEnergyQuery) => {
  return http.get<SystemSpace.DeviceListEnergy[]>("/device/list/energy", params, { loading: false })
}
// 生产设备 详情
export const deviceDetail = (id: number) => {
  return http.get<SystemSpace.DeviceDetail>(`/device/detail?id=${id}`)
}
// 生产设备 查询已绑定的生产设备ID集合
export const deviceIdsBound = () => {
  return http.get<number[]>(`/device/ids/bound`)
}

// ------------------计量设备------------------ //
// 计量设备 分页查询
export const meterPage = (params: SystemSpace.MeterPageQuery) => {
  return http.post<ResPage<SystemSpace.MeterPage>>("/meter/page", params)
}
// 计量设备 新增
export const addMeter = (params: SystemSpace.SaveMeter) => {
  return http.post<any>("/meter/add", params)
}
// 计量设备 编辑
export const modifyMeter = (params: SystemSpace.SaveMeter) => {
  return http.post<any>("/meter/modify", params)
}
// 计量设备 删除
export const deleteMeter = (params: { id: number }) => {
  return http.post<any>("/meter/remove", params)
}
// 计量设备 列表
export const meterList = () => {
  return http.get<SystemSpace.MeterList[]>("/meter/list")
}
// 计量设备 详情
export const meterDetail = (id: number) => {
  return http.get<SystemSpace.MeterDetail>(`/meter/detail?id=${id}`)
}
// 计量点位 分页查询
export const meterPointPage = (params: SystemSpace.MeterPointPageQuery) => {
  return http.post<ResPage<SystemSpace.MeterPointPage>>("/meter/point/page", params)
}
// 计量点位 新增
export const addMeterPoint = (params: SystemSpace.AddMeterPoint) => {
  return http.post<any>("/meter/point/add", params)
}
// 计量点位 删除
export const deleteMeterPoint = (params: { id: number }) => {
  return http.post<any>("/meter/point/remove", params)
}

// ------------------网关设备------------------ //
// 网关设备 分页查询
export const gatewayPage = (params: SystemSpace.GatewayPageQuery) => {
  return http.post<ResPage<SystemSpace.GatewayPage>>("/gateway/page", params)
}
// 网关设备 新增
export const addGateway = (params: SystemSpace.SaveGateway) => {
  return http.post<any>("/gateway/add", params)
}
// 网关设备 编辑
export const modifyGateway = (params: SystemSpace.SaveGateway) => {
  return http.post<any>("/gateway/modify", params)
}
// 网关设备 删除
export const deleteGateway = (params: { id: number }) => {
  return http.post<any>("/gateway/remove", params)
}
// 网关设备 列表
export const gatewayList = () => {
  return http.get<SystemSpace.GatewayList[]>("/gateway/list")
}
// 网关设备 详情
export const gatewayDetail = (id: number) => {
  return http.get<SystemSpace.GatewayDetail>(`/gateway/detail?id=${id}`)
}
// 获取设备统计数据
export const getDeviceStats = (deviceId: number) => {
  return http.get<{
    switchCount: number
    startRate: number
    abnormalStopTime: number
    plannedStopTime: number
  }>(`/device/stats/${deviceId}`)
}
